<?php
namespace app\controllers\api\fans;

use fate\http\Request;

use app\libs\LibUser;
use app\models\Fans;

class FollowedController extends \fate\web\PureController {

    public function run() {
        // 登录用户关注其他人
        $fansUid = LibUser::getLoginUid();
        if('' === $fansUid) {
            $this->ajaxReturn(null, 200001);
            exit;
        }

        $req = Request::getInstance();
        $uid = LibUser::decodeId($req->getParameter('uid'));

        if(!is_numeric($uid)) {
            $this->ajaxReturn(null, 300002);
            exit;
        }

        if($uid === $fansUid) {
            $this->ajaxReturn(null, 100011);
            exit;
        }

        $model = new Fans();
        $ret = $model->count('uid=' . $uid . ' and fans_uid=' . $fansUid);

        $this->ajaxReturn([
            'followed' => $ret > 0
        ]);
    }

}
